home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / lib-old / Para.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2005-10-18  |  10.0 KB  |  392 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. Int = type(0)
  5.  
  6. class Para:
  7.     
  8.     def __init__(self):
  9.         self.words = []
  10.         self.just = 'l'
  11.         self.indent_left = self.indent_right = self.indent_hang = 0
  12.         self.left = None
  13.         self.top = None
  14.         self.right = None
  15.         self.bottom = None
  16.         self.width = None
  17.         self.height = None
  18.         self.lines = None
  19.  
  20.     
  21.     def addword(self, d, font, text, space, stretch):
  22.         if font is not None:
  23.             d.setfont(font)
  24.         
  25.         width = d.textwidth(text)
  26.         ascent = d.baseline()
  27.         descent = d.lineheight() - ascent
  28.         spw = d.textwidth(' ')
  29.         space = space * spw
  30.         stretch = stretch * spw
  31.         tuple = (font, text, width, space, stretch, ascent, descent)
  32.         self.words.append(tuple)
  33.  
  34.     
  35.     def bgn_anchor(self, id):
  36.         self.words.append(id)
  37.  
  38.     
  39.     def end_anchor(self, id):
  40.         self.words.append(0)
  41.  
  42.     
  43.     def getlength(self):
  44.         total = 0
  45.         for word in self.words:
  46.             if type(word) is not Int:
  47.                 total = total + word[2] + word[3]
  48.                 continue
  49.         
  50.         return total
  51.  
  52.     
  53.     def tabto(self, tab):
  54.         total = 0
  55.         (as, de) = (1, 0)
  56.         for i in range(len(self.words)):
  57.             word = self.words[i]
  58.             if type(word) is Int:
  59.                 continue
  60.             
  61.             (fo, te, wi, sp, st, as, de) = word
  62.             self.words[i] = (fo, te, wi, sp, 0, as, de)
  63.             total = total + wi + sp
  64.         
  65.         if total < tab:
  66.             self.words.append((None, '', 0, tab - total, 0, as, de))
  67.         
  68.  
  69.     
  70.     def makehangingtag(self, hang):
  71.         self.tabto(hang)
  72.         self.indent_left = self.indent_left + hang
  73.         self.indent_hang = -hang
  74.  
  75.     
  76.     def layout(self, linewidth):
  77.         self.width = linewidth
  78.         height = 0
  79.         self.lines = lines = []
  80.         avail1 = self.width - self.indent_left - self.indent_right
  81.         avail = avail1 - self.indent_hang
  82.         words = self.words
  83.         i = 0
  84.         n = len(words)
  85.         lastfont = None
  86.         while i < n:
  87.             firstfont = lastfont
  88.             charcount = 0
  89.             width = 0
  90.             stretch = 0
  91.             ascent = 0
  92.             descent = 0
  93.             lsp = 0
  94.             j = i
  95.             while i < n:
  96.                 word = words[i]
  97.                 if type(word) is Int:
  98.                     if word > 0 and width >= avail:
  99.                         break
  100.                     
  101.                     i = i + 1
  102.                     continue
  103.                 
  104.                 (fo, te, wi, sp, st, as, de) = word
  105.                 if width + wi > avail and width > 0 and wi > 0:
  106.                     break
  107.                 
  108.                 if fo is not None:
  109.                     lastfont = fo
  110.                     if width == 0:
  111.                         firstfont = fo
  112.                     
  113.                 
  114.                 charcount = charcount + len(te) + (sp > 0)
  115.                 width = width + wi + sp
  116.                 lsp = sp
  117.                 stretch = stretch + st
  118.                 lst = st
  119.                 ascent = max(ascent, as)
  120.                 descent = max(descent, de)
  121.                 i = i + 1
  122.             while i > j and type(words[i - 1]) is Int and words[i - 1] > 0:
  123.                 i = i - 1
  124.             width = width - lsp
  125.             if i < n:
  126.                 stretch = stretch - lst
  127.             else:
  128.                 stretch = 0
  129.             tuple = (i - j, firstfont, charcount, width, stretch, ascent, descent)
  130.             lines.append(tuple)
  131.             height = height + ascent + descent
  132.             avail = avail1
  133.         self.height = height
  134.  
  135.     
  136.     def visit(self, wordfunc, anchorfunc):
  137.         avail1 = self.width - self.indent_left - self.indent_right
  138.         avail = avail1 - self.indent_hang
  139.         v = self.top
  140.         i = 0
  141.         for tuple in self.lines:
  142.             (wordcount, firstfont, charcount, width, stretch, ascent, descent) = tuple
  143.             h = self.left + self.indent_left
  144.             if i == 0:
  145.                 h = h + self.indent_hang
  146.             
  147.             extra = 0
  148.             if self.just == 'r':
  149.                 h = h + avail - width
  150.             elif self.just == 'c':
  151.                 h = h + (avail - width) / 2
  152.             elif self.just == 'lr' and stretch > 0:
  153.                 extra = avail - width
  154.             
  155.             v2 = v + ascent + descent
  156.             for j in range(i, i + wordcount):
  157.                 word = self.words[j]
  158.                 if type(word) is Int:
  159.                     ok = anchorfunc(self, tuple, word, h, v)
  160.                     if ok is not None:
  161.                         return ok
  162.                         continue
  163.                     continue
  164.                 
  165.                 (fo, te, wi, sp, st, as, de) = word
  166.                 if extra > 0 and stretch > 0:
  167.                     ex = extra * st / stretch
  168.                     extra = extra - ex
  169.                     stretch = stretch - st
  170.                 else:
  171.                     ex = 0
  172.                 h2 = h + wi + sp + ex
  173.                 ok = wordfunc(self, tuple, word, h, v, h2, v2, j == i, j == i + wordcount - 1)
  174.                 if ok is not None:
  175.                     return ok
  176.                 
  177.                 h = h2
  178.             
  179.             v = v2
  180.             i = i + wordcount
  181.             avail = avail1
  182.         
  183.  
  184.     
  185.     def render(self, d, left, top, right):
  186.         if self.width != right - left:
  187.             self.layout(right - left)
  188.         
  189.         self.left = left
  190.         self.top = top
  191.         self.right = right
  192.         self.bottom = self.top + self.height
  193.         self.anchorid = 0
  194.         
  195.         try:
  196.             self.d = d
  197.             self.visit(self.__class__._renderword, self.__class__._renderanchor)
  198.         finally:
  199.             self.d = None
  200.  
  201.         return self.bottom
  202.  
  203.     
  204.     def _renderword(self, tuple, word, h, v, h2, v2, isfirst, islast):
  205.         if word[0] is not None:
  206.             self.d.setfont(word[0])
  207.         
  208.         baseline = v + tuple[5]
  209.         self.d.text((h, baseline - word[5]), word[1])
  210.         if self.anchorid > 0:
  211.             self.d.line((h, baseline + 2), (h2, baseline + 2))
  212.         
  213.  
  214.     
  215.     def _renderanchor(self, tuple, word, h, v):
  216.         self.anchorid = word
  217.  
  218.     
  219.     def hitcheck(self, mouseh, mousev):
  220.         self.mouseh = mouseh
  221.         self.mousev = mousev
  222.         self.anchorid = 0
  223.         self.hits = []
  224.         self.visit(self.__class__._hitcheckword, self.__class__._hitcheckanchor)
  225.         return self.hits
  226.  
  227.     
  228.     def _hitcheckword(self, tuple, word, h, v, h2, v2, isfirst, islast):
  229.         if self.anchorid > 0:
  230.             if self.mouseh <= self.mouseh:
  231.                 pass
  232.             elif self.mouseh <= h2:
  233.                 if self.mousev <= self.mousev:
  234.                     pass
  235.                 elif self.mousev <= v2:
  236.                     self.hits.append(self.anchorid)
  237.                 
  238.  
  239.     
  240.     def _hitcheckanchor(self, tuple, word, h, v):
  241.         self.anchorid = word
  242.  
  243.     
  244.     def hasanchor(self, id):
  245.         if not id in self.words:
  246.             pass
  247.         return -id in self.words
  248.  
  249.     
  250.     def extract(self):
  251.         text = ''
  252.         for w in self.words:
  253.             if type(w) is not Int:
  254.                 word = w[1]
  255.                 if w[3]:
  256.                     word = word + ' '
  257.                 
  258.                 text = text + word
  259.                 continue
  260.         
  261.         return text + '\n'
  262.  
  263.     
  264.     def whereis(self, d, mouseh, mousev):
  265.         if mousev < self.top or mousev > self.bottom:
  266.             return None
  267.         
  268.         self.mouseh = mouseh
  269.         self.mousev = mousev
  270.         self.lastfont = None
  271.         self.charcount = 0
  272.         
  273.         try:
  274.             self.d = d
  275.             return self.visit(self.__class__._whereisword, self.__class__._whereisanchor)
  276.         finally:
  277.             self.d = None
  278.  
  279.  
  280.     
  281.     def _whereisword(self, tuple, word, h1, v1, h2, v2, isfirst, islast):
  282.         (fo, te, wi, sp, st, as, de) = word
  283.         if fo is not None:
  284.             self.lastfont = fo
  285.         
  286.         h = h1
  287.         if isfirst:
  288.             h1 = 0
  289.         
  290.         if islast:
  291.             h2 = 999999
  292.         
  293.         if self.mousev <= self.mousev:
  294.             pass
  295.         elif self.mousev <= v2:
  296.             if self.mouseh <= self.mouseh:
  297.                 pass
  298.             elif not self.mouseh <= h2:
  299.                 self.charcount = self.charcount + len(te) + (sp > 0)
  300.                 return None
  301.             
  302.         if self.lastfont is not None:
  303.             self.d.setfont(self.lastfont)
  304.         
  305.         cc = 0
  306.         for c in te:
  307.             cw = self.d.textwidth(c)
  308.             if self.mouseh <= h + cw / 2:
  309.                 return self.charcount + cc
  310.             
  311.             cc = cc + 1
  312.             h = h + cw
  313.         
  314.         self.charcount = self.charcount + cc
  315.         if self.mouseh <= (h + h2) / 2:
  316.             return self.charcount
  317.         else:
  318.             return self.charcount + 1
  319.  
  320.     
  321.     def _whereisanchor(self, tuple, word, h, v):
  322.         pass
  323.  
  324.     
  325.     def screenpos(self, d, pos):
  326.         if pos < 0:
  327.             (ascent, descent) = self.lines[0][5:7]
  328.             return (self.left, self.top, self.top + ascent, self.top + ascent + descent)
  329.         
  330.         self.pos = pos
  331.         self.lastfont = None
  332.         
  333.         try:
  334.             self.d = d
  335.             ok = self.visit(self.__class__._screenposword, self.__class__._screenposanchor)
  336.         finally:
  337.             self.d = None
  338.  
  339.         if ok is None:
  340.             (ascent, descent) = self.lines[-1][5:7]
  341.             ok = (self.right, self.bottom - ascent - descent, self.bottom - descent, self.bottom)
  342.         
  343.         return ok
  344.  
  345.     
  346.     def _screenposword(self, tuple, word, h1, v1, h2, v2, isfirst, islast):
  347.         (fo, te, wi, sp, st, as, de) = word
  348.         if fo is not None:
  349.             self.lastfont = fo
  350.         
  351.         cc = len(te) + (sp > 0)
  352.         if self.pos > cc:
  353.             self.pos = self.pos - cc
  354.             return None
  355.         
  356.         if self.pos < cc:
  357.             self.d.setfont(self.lastfont)
  358.             h = h1 + self.d.textwidth(te[:self.pos])
  359.         else:
  360.             h = h2
  361.         (ascent, descent) = tuple[5:7]
  362.         return (h, v1, v1 + ascent, v2)
  363.  
  364.     
  365.     def _screenposanchor(self, tuple, word, h, v):
  366.         pass
  367.  
  368.     
  369.     def invert(self, d, pos1, pos2):
  370.         if pos1 is None:
  371.             pos1 = (self.left, self.top, self.top, self.top)
  372.         else:
  373.             pos1 = self.screenpos(d, pos1)
  374.         if pos2 is None:
  375.             pos2 = (self.right, self.bottom, self.bottom, self.bottom)
  376.         else:
  377.             pos2 = self.screenpos(d, pos2)
  378.         (h1, top1, baseline1, bottom1) = pos1
  379.         (h2, top2, baseline2, bottom2) = pos2
  380.         if bottom1 <= top2:
  381.             d.invert((h1, top1), (self.right, bottom1))
  382.             h1 = self.left
  383.             if bottom1 < top2:
  384.                 d.invert((h1, bottom1), (self.right, top2))
  385.             
  386.             top1 = top2
  387.             bottom1 = bottom2
  388.         
  389.         d.invert((h1, top1), (h2, bottom2))
  390.  
  391.  
  392.